import Vue from 'vue'

export default {
	namespaced: true,
	/* 属性值 */
	state: {
		appName: '好老师',
		publish: { //发布配置相关
			uploadImgCount: 8, //上传图片张数
			contentTextCount: 156, //内容文本文字数量
		},
		loginInfo: { //登录信息
			// 用户信息
			user: {}, //username: "",openid: null,photo:''
			hasLogin: false,
			loginProvider: "",
			forcedLogin: false, //是否需要强制登录	
		},
		colors: ['yellow', 'olive', 'green', 'cyan', 'orange', 'blue', 'mauve', 'pink', 'grey',
			'red', 'purple', 'brown', 'gray', 'black' /*, 'white' */
		],
		//底部导航栏
		tabbars: {
			list: [{
					text: "首页",
					path: "/pages/index/index",
					icon: "cuIcon-homefill",
					iconType: "font", //值image图片 、font字体图标(默认值)
					name: "home"
				},
				{
					text: "发布",
					path: "",
					icon: "cuIcon-add",
					name: "publish",
					child: [{
							text: '说笑话',
							path: '/pages/joke/joke',
							icon: '/static/img/joke.png',
							iconType: "image", //值image图片 、font字体图标(默认值)
							name: 'joke'
						},
						{
							text: '讲故事',
							path: '/pages/joke/joke',
							icon: '/static/img/story.png',
							iconType: "image",
							name: 'story'
						},
						{
							text: '写案例',
							path: '/pages/joke/joke',
							icon: '/static/img/video.png',
							iconType: "image",
							name: 'case'
						}
					]
				},
				{
					text: "我的",
					path: "/pages/user/index",
					icon: "cuIcon-my",
					badge: 1,
					name: "ucenter"
				}
			]
		},
		//轮播图片
		swipers: {
			dotStyle: false,
			indicator: true,
			circular: true,
			autoplay: true,
			list: [{
				id: 0,
				type: 'image', //video
				url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big39000.jpg',
				text: ''
			}, {
				id: 1,
				type: 'image',
				url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big10001.jpg',
				text: ''
			}]
		},
		navs: {
			gridCol: 3,
			gridBorder: false,
			list: [{
				icon: 'cuIcon-cardboardfill',
				iconType: "font", //值image图片 、font字体图标(默认值)
				color: 'text-yellow',
				badge: 120,
				text: '捧腹笑话',
				path: "/pages/list/list?type=joke",
				name: "joke"
			}, {
				icon: 'cuIcon-recordfill',
				color: 'text-olive',
				badge: 1,
				text: '精彩故事',
				path: "/pages/list/list?type=story",
				name: "story"
			}, {
				icon: 'cuIcon-picfill',
				color: 'text-cyan',
				badge: 0,
				text: '生动案例',
				path: "/pages/list/list?type=case",
				name: "case"
			}]
		},
		notices: {
			list: [{
					text: 'uni-app行业峰会频频亮相，开发者反响热烈uni-app行业峰会频频亮相，开发者反响热烈',
					url: ""
				},
				{
					text: '36氪热文榜推荐、CSDN公号推荐 DCloud CEO文章uni-app行业峰会频频亮相，开发者反响热烈',
					url: ""
				}
			]
		},
		listNavs: {
			list: [{
				id: 0,
				text: 'HTML5',
			}, {
				id: 2,
				text: 'CSS3',
			}, {
				id: 3,
				text: 'JS',
			}, {
				id: 5,
				text: 'C#',
			}, {
				id: 6,
				text: 'Asp.net',
			}, {
				id: 7,
				text: 'Java',
			}, {
				id: 8,
				text: 'Python',
			}, {
				id: 9,
				text: 'Vue',
			}, {
				id: 10,
				text: 'SQL',
			}]
		},
		tags: {
			list: [{
				id: 0,
				text: 'HTML5',
			}, {
				id: 2,
				text: 'CSS3',
			}, {
				id: 3,
				text: 'JS',
			}, {
				id: 5,
				text: 'C#',
			}, {
				id: 6,
				text: 'Asp.net',
			}, {
				id: 7,
				text: 'Java',
			}, {
				id: 8,
				text: 'Python',
			}, {
				id: 9,
				text: 'Vue',
			}, {
				id: 10,
				text: 'SQL',
			}]
		}
	},
	/* 
		计算属性 
		定义 doneTodos:(state, getters,rootState)=>{}
		使用 store.getters.doneTodosCount
	*/
	getters: {

	},
	/* 
		计算方法
		定义 increment :function(state,data){}
		使用 store.commit('increment', data) or  store.commit({type:'increment',...data})
	 */
	mutations: {
		login(state, data) {
			state.loginInfo.hasLogin = true;
			state.loginInfo.user = data;
		},
		logout(state) {
			state.loginInfo.hasLogin = false;
			state.loginInfo.userInfo = {};
		},
		setOpenid(state, openid) {
			state.openid = openid
		}
	},
	/* 
		导步计算方法
		定义 incrementAsync  :function ({ commit, state,dispatch,rootState  },data){commit('increment',data)}
		使用 store.dispatch('incrementAsync', data) or  store.commit({type:'incrementAsync',...data})
	 */
	actions: {
		// lazy loading openid
		getUserOpenId: async function({
			commit,
			state
		}) {
			return await new Promise((resolve, reject) => {
				if (state.openid) {
					resolve(state.openid)
				} else {
					uni.login({
						success: (data) => {
							commit('login')
							setTimeout(function() { //模拟异步请求服务器获取 openid
								const openid = '123456789'
								console.log('uni.request mock openid[' + openid + ']');
								commit('setOpenid', openid)
								resolve(openid)
							}, 1000)
						},
						fail: (err) => {
							console.log('uni.login 接口调用失败，将无法正常使用开放接口等服务', err)
							reject(err)
						}
					})
				}
			})
		}
	}
}
